<?php

use Illuminate\Database\Seeder;

class CodeSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $codes = [
            [
                'name' => '用户状态',
                'code' => 'US',
                'values' => [
                    1 => '正常',
                    2 => '冻结',
                ]
            ],
            [
                'name' => '导入类型',
                'code' => 'IT',
                'values' => [

                ]
            ],
            [
                'name' => '客户端类型',
                'code' => 'CT',
                'values' => [
                    1 => '管理后台'
                ]
            ]
        ];

        $insertCodeData = [];
        $insertCodeValueData = [];
        $time = time();
        foreach ($codes as $code) {
            $insertCodeData[] = [
                'name' => $code['name'],
                'code' => $code['code'],
                'created_at' => $time,
                'updated_at' => $time
            ];
            foreach ($code['values'] as $k => $v) {
                $insertCodeValueData[] = [
                    'name' => $v,
                    'code' => $code['code'],
                    'value' => $k,
                    'created_at' => $time,
                    'updated_at' => $time
                ];
            }
        }
        \App\Models\Code::query()->insert($insertCodeData);
        \App\Models\CodeValue::query()->insert($insertCodeValueData);
    }
}
